import { createRouter, createWebHashHistory } from 'vue-router'
import { AppRoutes } from './routes'

const AppRouter = createRouter({
  history: createWebHashHistory(),
  routes: AppRoutes
})

// 前置守卫
AppRouter.beforeEach((to) => {
  // 判断是否已经在登陆页
  if (to.path === '/login') {
    return
  }
  // 不在登录页 登录验证
  if (!localStorage.getItem('TOKEN')) {
    return '/login'
  }
})

// 后置守卫
AppRouter.afterEach((to) => {})

export default AppRouter
